/**
 */
;
(function(){
'use strict';
	
	var app = angular.module('fwa.mainApp');
	app.controller('WarningViewCtrl', ['$scope','$modal','$state', 
	                                  '$stateParams','WarningAddService','BaseURL','Modal',
	    function ($scope,$modal,$state,$stateParams,WarningAddService,baseUrl,Modal) {
		$scope.serv = WarningAddService;
		var warnNo=$stateParams.warnNo,
		    noticeRequirement="";
		var codeType=['WARN_SOURCE','WARN_SOURCE_TYPE','PROCESS_TYPE'];
		$scope.warningFrom={};
		$scope.warnInsurCount=0;
		$scope.warnStaffCount=0;
		$scope.warnMedicalCount=0;
		$scope.warnInsurData=[];
		$scope.warnStaffData=[];
		$scope.warnMedicalData={};
		$scope.warnScreenList=[];
		WarningAddService.getHcpmsWarning({warnNo:warnNo})
		.success(function(res){
				$scope.warningFrom=res.warnInfo;
                $scope.warnScreenList=res.warnScreenList;
                $scope.warnMedicalData=res.warnMedicalInfo;
        		$scope.warnStaffData=res.warnStaffList;
        		$scope.warnInsurData=res.warnInsuranceList;
        		$scope.notice=res.notice;
        		$scope.warnInsurCount=$scope.warnInsurData.length;
        		$scope.warnStaffCount=$scope.warnStaffData.length;
        		setWarningInfoValue(res.warnInfo);
	     });
		
		function setWarningInfoValue(info){
			$scope.warningFrom.date={};
			$scope.warningFrom.date.start=info.startDate;
			$scope.warningFrom.date.end=info.endDate;
			WarningAddService.getHcpmsCodeList(codeType).success(function(response){
				angular.forEach(response.result,function(data,index){
					 if('WARN_SOURCE' === data.codeType&&info.source===data.codeNo){
						    $scope.warningFrom.sourceName = data.codeDesc;
						}else if('WARN_SOURCE_TYPE' === data.codeType&&info.sourceType===data.codeNo){
							$scope.warningFrom.sourceTypeName = data.codeDesc;
						}else if('PROCESS_TYPE' === data.codeType && info.process===data.codeNo){
							$scope.warningFrom.processName = data.codeDesc;
						}
			    });
		    });
		}
		//查看案件来源
		$scope.viewDetailWarning = function(){
			var scope = $scope.$new();
			scope.warningFrom = $scope.warningFrom;
			var modalInstance = $modal.open({
	      	      templateUrl: baseUrl +'views/hcpms/warning/warnView/warningViewBase_view.html',
	      	      backdrop:'static',
				  size:'sm',
				  scope:scope,
	      	      controller:function($modalInstance,$scope){
					  $scope.onOk = function(){
				  		   $modalInstance.dismiss();
				  	   }	
				  }
	  	    });	
		}
		//自查通知书
		$scope.warningNoticeDialog = function() {
			var scope = $scope.$new();
			scope.warningNotice=$scope.notice;
			scope.warningNotice.date=WarningAddService.setPriodDate(scope.warningNotice.datestart,scope.warningNotice.dateend);
			
			var modalInstance = $modal.open({
	      	      templateUrl: baseUrl +'views/hcpms/warning/warnView/warningViewNotice_view.html',
	      	      backdrop:'static',
				  size:'sm',
				  scope:scope,
	      	      controller:function($modalInstance,$scope){
					  $scope.onOk = function(){
				  		   $modalInstance.dismiss();
				  	   }	
				  }
	  	    });
		}
		//查看参保人员详细信息
		$scope.viewInsurList = function(){
			var scope = $scope.$new();
			scope.warnInsuranceList=$scope.warnInsurData;
			var modalInstance = $modal.open({
			      templateUrl: baseUrl+'views/hcpms/warning/warnView/warningViewInsurance_view.html',
			      backdrop:'static',
				  size:'sm',
				  scope:scope,
				  controller:function($modalInstance,$scope){
					  $scope.onOk = function(){
				  		   $modalInstance.dismiss();
				  	   }	
				  }
			    });
			
		}
		//查看医护人员详细信息
		$scope.viewStaffList = function(){
			var scope = $scope.$new();
			scope.warnStaffList=$scope.warnStaffData;
			var modalInstance = $modal.open({
				  templateUrl: baseUrl+'views/hcpms/warning/warnView/warningViewStaff_view.html',
			      backdrop:'static',
				  size:'sm',
				  scope:scope,
				  controller:function($scope,$modalInstance){
		  	          //取消或或者直接关闭
					  $scope.onOk = function(){
						  $modalInstance.dismiss();
			          }	
				  }
			    });
			
		}
		$scope.tabs=[{label:'网上筛查',id:0,url:'views/hcpms/warning/warnView/warningViewScreen_view.html'}];
		$scope.selectedTab = $scope.tabs[0];
		$scope.currentTabIndex = 0;

		$scope.tabClick = function(tab) {
			$scope.selectedTab = tab;
			$scope.currentTabIndex=tab.id;
		}
	   $scope.backWarning = function(){
        	$state.go("warning.warningList");
        }
	}]);
})();